package com.drools.userguide._3_batchExecute;

import com.drools.userguide._1_onlyOneRule.Applicant;
import com.drools.userguide._2_twoRules.Application;
import org.kie.api.KieServices;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class Test {

    @org.junit.Test
    public void test() {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kContainer = kieServices.getKieClasspathContainer();
        StatelessKieSession kSession = kContainer.newStatelessKieSession();
        KieCommands kieCommands = kieServices.getCommands();
        List<Command> cmds = new ArrayList<Command>();
        Applicant applicant = new Applicant("Mr John Smith", 20);
        Application application = new Application();
        cmds.add(kieCommands.newInsert(applicant, "applicant"));
        cmds.add(kieCommands.newInsert(application, "application"));
        ExecutionResults bresults = kSession.execute(kieCommands.newBatchExecution(cmds));
        Applicant outApplicant = (Applicant) bresults.getValue("applicant");
        Application outApplication = (Application) bresults.getValue("application");
        assertTrue(outApplicant.isValid());
        assertTrue(outApplication.isValid());
    }
}
